package Exercise.override;
import java.util.HashSet;
import java.util.Set;
public class G {
    static class Student{
        String name;  
        int age;        
        Student(String name,int age){       
        this.name=name;        
        this.age=age;      
        }
        public int hashCode(){

            int res=17;
            
            res=31*res+age;
            
            res=31*res+name.hashCode();
            
            return res;
            
            }
        public boolean equals(Object obj){
            System.out.println("--------equals()-----------:"+obj);  //--------equals()-----------:Exercise.override.G$Student@215b6         
            if(obj==null){         
            return false;          
            }         
            if(!(obj instanceof Student)){          
            return false;        
            }else{          
            Student oth=(Student)obj;       
            return this.age==oth.age&&this.name==oth.name;        
            }        
            //return true;      
            }
    }
    public static void main(String[] args){
        Set<Student> set=new HashSet<Student>();       
        Student stu1=new Student("ydj",26);      
        Student stu2=new Student("ydj",26);       
        set.add(stu1);       
        set.add(stu2);       
        System.out.println("set.size():"+set.size());//set.size():1
        
    }
    m
}
